<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Shadowsocks共享平台</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/layui.css') }}"  media="all">
    </head>
    <body>
        <div class="layui-container">
            <blockquote class="layui-elem-quote layui-text">SSSERVER.CC</blockquote>
            <div class="layui-row">
                <div class="layui-tab layui-tab-card" lay-filter="type">
                    <ul class="layui-tab-title">
                        <li class="layui-this" lay-id="1">节点状态</li>
                        <li lay-id="2">用户列表</li>
                        <li lay-id="3">添加用户</li>
                        <li lay-id="4">共享节点</li>
                        <li lay-id="5">下载中心</li>
                        <li lay-id="6">生成二维码</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form">
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="150">
                                        <col width="150">
                                        <col width="200">
                                        <col>
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th>域名</th>
                                            <th>内存</th>
                                            <th>状态</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for HOST in HOSTLIST %}
                                        <tr>
                                            <td>{{ HOST.Addr }}</td>
                                            <td>{{ HOST.MemoryBytes }} MB</td>
                                            {% if HOST.State == 'ready' %}
                                                <td><span class="layui-badge layui-bg-green">正常</span></td>
                                            {% elif HOST.State == 'down' %}
                                                <td><span class="layui-badge">异常</span></td>
                                            {% else %}
                                                <td><span class="layui-badge layui-bg-gray">未知</span></td>
                                            {% endif %}
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form">
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="150">
                                        <col width="150">
                                        <col width="200">
                                        <col>
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th>用户</th>
                                            <th>端口</th>
                                            <th>加密方式</th>
                                            <th>密码</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for USER in USERLIST %}
                                        <tr>
                                            <td>{{ USER.name }}</td>
                                            <td>{{ USER.PublishedPort }}</td>
                                            <td>aes-256-cfb</td>
                                            <td>{{ USER.password }}</td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <form class="layui-form" action="/adduser.html" method="post">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">用户名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="ssuser" lay-verify="ssuser" autocomplete="off" placeholder="请输入Shadowsocks用户名" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">密码</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="sspass" lay-verify="sspass" autocomplete="off" placeholder="请输入Shadowsocks密码" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">端口</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="ssport" lay-verify="ssport" autocomplete="off" placeholder="请输入Shadowsocks端口" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">口令</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="addpass" lay-verify="addpass" autocomplete="off" placeholder="请输入认证口令" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即添加</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="layui-tab-item">
                            <form class="layui-form" action="/addhost.html" method="post">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">IP 地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="sship" lay-verify="sship" autocomplete="off" placeholder="请输入主机 IP 地址" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">SSH 端口</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="sshport" value="22" lay-verify="sshport" autocomplete="off" placeholder="请输入主机 SSH 端口" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">SSH 用户</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="sshuser" lay-verify="sshuser" autocomplete="off" placeholder="请输入主机 SSH 用户" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">SSH 密码</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="sshpass" lay-verify="sshpass" autocomplete="off" placeholder="请输入主机 SSH 密码" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">系统类型</label>
                                    <div class="layui-input-inline">
                                        <select name="os" lay-verify="required" lay-search="">
                                            <option value="" selected="">请选择系统类型</option>
                                            <option value="CentOS">CentOS</option>
                                            <option value="Ubuntu">Ubuntu</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">所属地区</label>
                                    <div class="layui-input-block">
                                        <input type="radio" name="diqu" value="hk" title="香港" checked="">
                                        <input type="radio" name="diqu" value="us" title="美国">

                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即添加</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form">
                                <table class="layui-table">
                                    <colgroup>
                                        <col width="150">
                                        <col width="150">
                                        <col width="200">
                                        <col>
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th>平台</th>
                                            <th>链接</th>
                                            <th>备注</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>Linux</td>
                                            <td>
                                                <a href="https://github.com/the0demiurge/CharlesScripts/blob/master/charles/bin/ssr">Linux 客户端一键安装配置使用脚本</a>
                                            </td>
                                            <td>命令行界面， Mac 也能用，使用方法见注释</td>
                                        </tr>
                                        <tr>
                                            <td>Terminal</td>
                                            <td>
                                                <a href="https://the0demiurge.blogspot.jp/2017/07/aptshadowsocks-tsocks.html">tsocks</a>
                                            </td>

                                            <td>安装使用教程</td>
                                        </tr>
                                        <tr>
                                            <td>Windows</td>
                                            <td>
                                                <a href="http://ys-f.ys168.com/598741933/iTjHSWk4J536H265KM5/Shadowsocks.exe">Windows 推荐使用</a>
                                            </td>
                                            <td>Windows 推荐使用</td>
                                        </tr>
                                        <tr>
                                            <td>Android</td>
                                            <td>
                                                <a href="http://ys-n.ys168.com/598741957/jRgMVTn4J536H26KKM6/shadowsocks.apk">Android 客户端</a>
                                            </td>
                                            <td>中文版</td>
                                        </tr>
                                        <tr>
                                            <td>MacOS</td>
                                            <td>
                                                <a href="http://ys-n.ys168.com/598741957/jRgMVTn4J536H26KKM6/shadowsocks.apk">ShadowsocksX-NG</a>
                                            </td>
                                            <td>Mac 也能用 Linux 版的</td>
                                        </tr>
                                        <tr>
                                            <td>IOS</td>
                                            <td>
                                                <a href="https://github.com/Alvin9999/new-pac/wiki/%E8%8B%B9%E6%9E%9C%E6%89%8B%E6%9C%BA%E7%BF%BB%E5%A2%99%E8%BD%AF%E4%BB%B6">只有中国 App Store 帐号</a>，
                                                <a href="https://github.com/shadowsocks/shadowsocks-iOS/wiki/Help">美区 App Store</a>
                                            </td>
                                            <td>只有中国区 App Store的话会麻烦一些</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <form class="layui-form" action="/erweima.html" method="post">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">主机</label>
                                    <div class="layui-input-block">
                                        <select name="hostname" lay-filter="aihao">
                                            <option value="" selected=""></option>
                                            {% for HOST in HOSTLIST %}
                                            <option value="{{ HOST.Addr }}">{{ HOST.Addr }}</option>
                                            {% endfor %}
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">服务端口</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="port" lay-verify="sshport" autocomplete="off" placeholder="请输入SS 端口" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">密码</label>
                                    <div class="layui-input-block">
                                        <input type="password" name="password" lay-verify="sshuser" autocomplete="off" placeholder="请输入连接密码" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <label class="layui-form-label">加密方式</label>
                                    <div class="layui-input-block">
                                        <select name="method" lay-filter="aihao">
                                            <option value=""></option>
                                            <option value="aes-256-cfb" selected="">aes-256-cfb</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即添加</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script src="{{ url_for('static', filename='layui.js') }}" charset="utf-8"></script>
        <script>
            layui.use('element', function(){
                var $ = layui.jquery,element = layui.element;
                var layid = location.hash.replace(/^#type=/, '');
                element.tabChange('type', layid);
                element.on('tab(type)', function(elem){
                    location.hash = 'type='+ $(this).attr('lay-id');
                });
            });
        </script>
        <script>
            function isValidIP(ip) {
                var reg =  /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
                return reg.test(ip);
            }
            function isPort(str) {
                var parten=/^(\d)+$/g;
                if(parten.test(str)&&parseInt(str)<=65535&&parseInt(str)>=0){
                    return true;
                 }else{
                    return false;
                 }
            }
            layui.use(['form', 'layedit', 'laydate'], function(){
                var form = layui.form,layer = layui.layer,layedit = layui.layedit;

                //自定义验证规则
                form.verify({
                    sship: function(value){
                        if(value.length <= 0){
                            return '请输入IP 地址';
                        }else if (!isValidIP(value)){
                            return '请输入正确的 IP 地址';
                        }
                    },
                    sshport: function(value){
                        if(value.length <= 0){
                            return '请输入SSH 端口';
                        } else if(!isPort(value)){
                            return '请输入正确的端口';
                        }
                    },
                    sshuser: function(value){
                        if(value.length <= 0){
                            return '请输入SSH 用户';
                        }
                    },
                    sshpass: function(value){
                        if(value.length <= 0){
                            return '请输入SSH 密码';
                        }
                    },
                });

                //监听提交
                form.on('submit(demo1)', function(data){
                    $.getJSON(
                        "addhost.html",
                        JSON.stringify(data.field)
                        ,function(result){
                            console.log(result);
                        }
                    );
                    return false;
                });
            });
        </script>
    </body>
</html>